import request from "@/utils/request";
const baseUrl = "/core/messageConfig";

const messageConfigApi = {
  // 获取消息配置列表
  getMessageConfigList(query: MessageConfigQuery) {
    const queryStr = encodeURIComponent(JSON.stringify(query));
    return request<any, PageResult<MessageConfigList[]>>({
      url: `${baseUrl}/getMessageConfigs?object=${queryStr}`,
      method: "get",
    });
  },
  //获取消息配置详情
  getMessageConfigDetail(id: number) {
    return request<any, MessageConfigList>({
      url: `${baseUrl}/getMessageConfigDetail?id=${id}`,
      method: "get",
    });
  },

  // 新增消息配置
  addMessageConfig(data: any) {
    return request({
      url: `${baseUrl}/createMessageConfig`,
      method: "post",
      data,
    });
  },

  // 更新消息配置
  updateMessageConfig(data: any) {
    return request({
      url: `${baseUrl}/updateMessageConfig`,
      method: "post",
      data,
    });
  },

  // 删除消息配置
  deleteMessageConfig(id: number) {
    return request({
      url: `${baseUrl}/deleteMessageConfig`,
      method: "post",
      data: { id },
    });
  },

  // 更新消息配置状态 0=禁用,1=启用
  updateMessageConfigStatus(id: number, status: number) {
    return request({
      url: `${baseUrl}/updateStatus`,
      method: "post",
      data: { id, status },
    });
  },
};
export default messageConfigApi;

export interface MessageConfigQuery extends PageQuery {
  title?: string;
  status?: number;
}

//消息列表
export interface MessageConfigList {
  createTime: string;
  id: number;
  msgType: string;
  receiveRoleIds: string;
  receiveUserIds: string;
  receiveType: number;
  status: number;
  updateTime: string;
  publisherName: string;
}

//消息表单
export interface MessageConfigForm {
  createTime: string;
  id: number;
  receiveType: number;
  msgType: string;
  receiveRoleIds: number[];
  receiveUserIds: number[];
  status: number;
  updateTime: string;
  publisherName: string;
}
